package com.enlorenz.common.security.des;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

/**
 * 三倍DES
 * @author Karma
 *
 */
public class Coder4TripleDES extends AbstractDes{

	@Override
	protected String getDesTypeEnum() {
		return DesTypeEnum.DESede.name();
	}
	
	public static byte[] encryptDES(byte[] encryptbyte, byte[] encryptKey) throws Exception {  
        SecretKeySpec key = new SecretKeySpec(encryptKey, "DESede");  
        Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");  
        cipher.init(Cipher.ENCRYPT_MODE, key);  
        byte[] encryptedData = cipher.doFinal(encryptbyte);  
        return encryptedData;
    }
	
	public static byte[] des(byte[] encryptbyte, byte[] encryptKey) throws Exception {  
        SecretKeySpec key = new SecretKeySpec(encryptKey, "DESede");  
        Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");  
        cipher.init(Cipher.DECRYPT_MODE, key);  
        byte[] encryptedData = cipher.doFinal(encryptbyte);  
        return encryptedData;
    }
	
}
